package com.github.thinwonton.springboot.showcase.transaction.propagation.service.nested_tx;

import com.github.thinwonton.springboot.showcase.transaction.propagation.dao.AccountDao;
import com.github.thinwonton.springboot.showcase.transaction.propagation.domain.Account;
import com.github.thinwonton.springboot.showcase.transaction.propagation.service.propagation_required.PaymentService;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Currency;

@Service
public class NestedTxAccountService {

	@Autowired
	private AccountDao accountDao;

	@Transactional
	public void saveAccount(Account record) {
		accountDao.insert(record);
//		throw new RuntimeException("测试事务");
	}

	public void doSomething() {
		Account account = new Account();
		Long id = System.currentTimeMillis();
		account.setId(id);
		account.setMoney(BigDecimal.ZERO);
//		saveAccount(account);
		((NestedTxAccountService) AopContext.currentProxy()).saveAccount(account);
	}
}
